<%@page import="com.shuohe.entity.system.user.User"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page language="java" import="java.util.*"%>

<%@ page import="com.shuohe.util.json.*" %>

<%@ page import="java.io.PrintWriter"%> 
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
    PrintWriter ss = response.getWriter();
    User user = null;
    String userStr = null;
    String pid = request.getParameter("pid");
    try
    {

        user = (User)session.getAttribute("user");
        if(user == null)
        {
            System.out.println("user = null");
            //response.sendRedirect(basePath+"/pages/login.jsp");
            String topLocation = "<script>top.location.href=\""+basePath+"/pages/login.jsp\"</script>";
            ss.print(topLocation);
        }
        userStr = Json.toJsonByPretty(user);
    }
        catch(Exception e)
    {
        String topLocation = "<script>top.location.href=\""+basePath+"/pages/login.jsp\"</script>";
        ss.print(topLocation);
        e.printStackTrace();
    }  
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>绩效管理列表</title>


    <link type="text/css" href="/TopJUI/topjui/css/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="/TopJUI/topjui/themes/default/topjui.green.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="/TopJUI/topjui/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- jQuery相关引用 -->
    <script type="text/javascript" src="/TopJUI/topjui/plugins/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/TopJUI/topjui/plugins/jquery/jquery.cookie.js"></script>
    <!-- TopJUI框架配置 -->
    <script type="text/javascript" src="/TopJUI/static/public/js/topjui.config.js"></script>
    <!-- TopJUI框架核心-->
    <script type="text/javascript" src="/TopJUI/topjui/js/topjui.core.min.js"></script>
    <!-- TopJUI中文支持 -->
    <script type="text/javascript" src="/TopJUI/topjui/js/locale/topjui.lang.zh_CN.js"></script>

    <script type="text/javascript" src="/pages/js/moment.min.js"></script>
    <script type="text/javascript" src="/pages/js/layer/layer.js"></script>
    <script type="text/javascript" src="/pages/js/util.js"></script>

    <script type="text/javascript" src="/pages/js/base-loading.js"></script>
    <script type="text/javascript" src="/pages/js/shuoheUtil.js"></script>

    <style type="text/css">
        html, body{ margin:0; height:100%; }
    </style>

</head>
<body class="easyui-layout">

  <!--   <div data-options="region:'west',iconCls:'icon-reload',title:'',split:true" style="width:15%;">           
        <table id="tt" style="height:100%;width: 100%;" title="" data-options="
                  idField:'id',
                  treeField:'project_name',
                  method:'get'
                ">
          <thead>
              <tr>
                  <th field="project_name" width="100%">职位</th>
                  <th field="id" width="0px" hidden="true">序列</th>
              </tr>
          </thead>
        </table>        
    </div> -->

    <div data-options="region:'center',iconCls:'icon-reload',title:'',split:true" style="width:100%;height: 100%">
        <table id="dg" class='easyui-datagrid' style="width:99%;height:100%" title="" data-options="
                  rownumbers:false,
                  singleSelect:false,
                  autoRowHeight:false,
                  pagination:true,
                  fitColumns:false,
                  striped:true,
                  checkOnSelect:true,
                  selectOnCheck:true,
                  collapsible:false, 
                  toolbar:'#tb',
                  pageSize:20">
            <thead>
              <tr href="#">
                    <th data-options="field:'ck',checkbox:true"></th>
                    <th field="id" align="center" hidden ="true">id</th>
                    <th field="name" width="6%" align="center">任务所属人</th>
                    <th field="taskContent" width="20%" formatter='Easyui.Datagraid.formatterChinese'>任务内容</th>
                    <th field="period" align="center" width="15%" align="center" hidden="true">结算周期</th>
                    <th field="startDate" width="8.5%" align="center">结算起始日期</th>
                    <th field="endDate" width="8.5%" align="center">结算结束日期</th>
                    <th field="taskPerformance" width="10%" align="center">任务绩效</th>
                    <th field="duration" width="7%" align="center" formatter="formatterDuration">时间间隔</th>
                    <th field="doTime" width="12.5%" align="center">结算时间</th>
                    <th field="commitStatus" width="10%" align="center" formatter="formatterCommitStatus">提报状态</th>
                    <th field="handle" width="11%" formatter="handle" align="center">操作</th>
              </tr>
            </thead>
          </table>
          <div id="tb" style="height:35px">            
            <a id='btnInsert' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-download',plain:true" onclick="exportExcel()" style="margin-left:5px">导出</a>          
            <form id="queryForm" class="search-box">
                  <input class="easyui-combobox" id='query_name' data-options="prompt:'姓名'">
                  <input class="easyui-combobox" id='query_commit_status' data-options="prompt:'提报状态'">
                  <input class="easyui-datebox" id='query_start_date' data-options="prompt:'起始时间'"><span style="margin: 7px">至:</span><input class="easyui-datebox" id='query_end_date' data-options="prompt:'截止时间'">
                  <a id='btnQuery' href="#" class="easyui-linkbutton" btnCls='topjui-btn-normal' plain="true" iconCls="fa fa-search" onclick="functionQuery()" style="margin-left: 0px">搜索</a>          
                  <a id='btnClear' href="#" class="easyui-linkbutton" btnCls='topjui-btn-normal' plain="true" iconCls="fa fa-refresh" onclick="functionClear()" style="margin-left: 0px">清除</a>  
            </form>            
          </div>
       </div>
    </div>
  <script type="text/javascript">
    var project = new Object();
    var user = <%=userStr%>;
    var commitSelectData = [{"id": "0","text":"未提报"},     //学生对象的键为名字,值为对应属性
    	{"id": "1","text":"已提报"}];
    $(function(){
    	loadDg();
    	initSelect();
    });
    
    function loadDg() {
        $('#dg').datagrid({
          url: '/develop/url/getUrl.do',
          queryParams: {
        	'name':'getPerformanceList',
        	'userName':$('#query_name').combobox('getText'),
        	'commitStatus':$('#query_commit_status').combobox('getValue'),
        	'startDate':$('#query_start_date').datebox('getValue'),
        	'endDate':$('#query_end_date').datebox('getValue')
          },
          method: 'get'
        })
      }
    
    function formatterCommitStatus(value,row,index){
  	  var reVal;
  	  if(value=='0'){
  		  reVal='<font color="red">未提报</font>';
  	  }else if(value=='1'){
  		reVal='<font color="green">已提报</font>';
  	  }
  	   return reVal;
     }
    
    function formatterDuration(value,row,index){
    	  
    	   return value+"天";
    }
    
    function handle(value,row,index){
    	var btn = "";
        btn = '<a class="editcls" onclick="commit(\''+ row.id+'\')" href="javascript:void(0)">提报</a>' + "&nbsp;&nbsp;&nbsp;&nbsp;";
        btn += '<a class="editcls" onclick="cancel(\''+ row.id +'\')" href="javascript:void(0)">撤销</a>';
        return btn;
    }
    
    function commit(id){
    	$.ajax({
            url:'/pm2/project/changeCommitStatus.do',
            type: "POST",
            dataType: 'json',
            data: {
                'master_plan_id': id,
                'commit_status':'1'
            },
            error: function() //失败
            {
                shuoheUtil.layerTopMaskOff();
            },
            success: function(data) //成功
            {
                shuoheUtil.layerTopMaskOff();
                if (data.result == true) {
                    shuoheUtil.layerClose();
                    updateSuccess();
                } else
                    shuoheUtil.layerMsgCustom(data.describe);
            }
        });
    }
    
    function cancel(id){
    	$.ajax({
    		url:'/pm2/project/changeCommitStatus.do',
            type: "POST",
            dataType: 'json',
            data: {
                'master_plan_id': id,
                'commit_status':'0'
            },
            error: function() //失败
            {
                shuoheUtil.layerTopMaskOff();
            },
            success: function(data) //成功
            {
                shuoheUtil.layerTopMaskOff();
                if (data.result == true) {
                    shuoheUtil.layerClose();
                    updateSuccess();
                } else
                    shuoheUtil.layerMsgCustom(data.describe);
            }
        });
    }
    
    function updateSuccess(){
    	$('#dg').datagrid('reload');
    }
    function initSelect(){
    	$('#query_name').combobox({
            url: '/develop/url/getUrl.do',
            queryParams: {
          	'name':'getUserSelectList'
            },
            valueField: 'id',
            textField: 'actual_name',
            method: 'get'
          });
    	
    	$('#query_commit_status').combobox({
    		data:commitSelectData,
            valueField: 'id',
            textField: 'text',
            method: 'get'
          });
    }
    function functionQuery(){
    	loadDg();
    }
    
    function functionClear(){
    	$('#query_name').combobox('clear');
    	$('#query_commit_status').combobox('clear');
    	$('#query_start_date').datebox('clear');
    	$('#query_end_date').datebox('clear');
    	loadDg();
    }
    function exportExcel(){
    	var url = "/pm2/project/exportExcel.do";
  	    window.open(url);
    }
	</script>
</body>
</html>
